import os
import subprocess

# Python文件路径
file_path = 'roi.py'

# 读取Python文件内容
with open(file_path, 'r') as file:
    lines = file.readlines()

# 提取导入的库
imports = [line for line in lines if line.startswith('import') or line.startswith('from')]
libs = set()
for imp in imports:
    parts = imp.split()
    if parts[0] == 'import':
        libs.add(parts[1].split('.')[0])
    elif parts[0] == 'from':
        libs.add(parts[1].split('.')[0])

# 过滤掉Python标准库
# 这里只是一个简单的示例，可能需要根据实际情况添加更多的标准库
standard_libs = {'os', 'sys', 'json', 'setting'}
libs = libs - standard_libs
lib_mapping = {
    'wx': 'wxPython',
    'cv2': 'opencv-python',
}
# 使用pip安装库
for lib in libs:
    correct_lib_name = lib_mapping.get(lib, lib)  # 获取库的正确名称，如果没有映射则使用原名称
    subprocess.run(['pip', 'install', correct_lib_name])